package com.jy.controller.filemanager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jy.common.ajax.AjaxRes;
import com.jy.common.mybatis.Page;
import com.jy.common.utils.base.Const;
import com.jy.controller.base.BaseController;
import com.jy.entity.filemanager.TSLog;
import com.jy.entity.filemanager.TSProject;
import com.jy.service.filemanager.operlog.OperLogService;

@Controller
@RequestMapping("/operLog")
public class OperLogController extends BaseController<TSProject> {

	@Autowired
	private OperLogService service;

	/**
	 * @api {post} /operLog/findBypage  日志分页列表查询
	 * 
	 * @apiName findBypage
	 * @apiGroup operLog
	 * @apiParam {Object} Page<TSProduct> 分页对象
	 * @apiSuccess {Object} obj 1.resMsg 2.obj
	 * @apiParam {Object} Ts  日志对象
	 */
	@RequestMapping(value = "findBypage", method = RequestMethod.POST)
	@ResponseBody
	public AjaxRes index(Page<TSLog> page, TSLog o) {
		AjaxRes ar = getAjaxRes();
		try {
			Page<TSLog> result = service.findByPage(o, page);
			Map<String, Object> p = new HashMap<String, Object>();
			p.put("list", result);
			ar.setSucceed(p);
		} catch (Exception e) {
			logger.error(e.toString(), e);
			ar.setFailMsg(Const.DATA_FAIL);
		}
		return ar;
	}

	/**
	 * @api {post} /operLog/find  日志查询
	 * 
	 * @apiName find
	 * @apiGroup operLog
	 * @apiParam {Object} Page<TSProduct> 分页对象
	 * @apiSuccess {Object} obj 1.resMsg 2.obj
	 * @apiParam {Object} TSLog  日志对象
	 */
	@RequestMapping(value = "find", method = RequestMethod.POST)
	@ResponseBody
	public AjaxRes find(TSLog o) {
		AjaxRes ar = getAjaxRes();
		try {
			List<TSLog> list = service.find(o);
			TSLog obj = list.get(0);
			ar.setSucceed(obj);
		} catch (Exception e) {
			logger.error(e.toString(), e);
			ar.setFailMsg(Const.DATA_FAIL);
		}
		return ar;
	}

	/**
	 * @api {post} /operLog/add  项目新增
	 * 
	 * @apiName add
	 * @apiGroup operLog
	 * @apiParam {Object} Page<TSProduct> 分页对象
	 * @apiSuccess {Object} obj 1.resMsg 2.obj
	 * @apiParam {Object} TSLog 日志对象
	 */
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody
	public AjaxRes add(TSLog o) {
		AjaxRes ar = getAjaxRes();
		try {
			o.setId(get32UUID());
			int res = service.creatLog(o);
			if (res == 1)
				ar.setSucceedMsg(Const.SAVE_SUCCEED);
			else
				ar.setFailMsg(Const.SAVE_FAIL);
		} catch (Exception e) {
			logger.error(e.toString(), e);
			ar.setFailMsg(Const.SAVE_FAIL);
		}
		return ar;
	}

	/**
	 * @api {post} /operLog/update  日志跟新
	 * 
	 * @apiName update
	 * @apiGroup operLog
	 * @apiParam {Object} Page<TSProduct> 分页对象
	 * @apiSuccess {Object} obj 1.resMsg 2.obj
	 * @apiParam {Object} TSLog  日志对象
	 */
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public AjaxRes update(TSLog o) {
		AjaxRes ar = getAjaxRes();
		try {
			int res = service.updateLog(o);
			if (res == 1)
				ar.setSucceedMsg(Const.UPDATE_SUCCEED);
			else
				ar.setFailMsg(Const.UPDATE_FAIL);
		} catch (Exception e) {
			logger.error(e.toString(), e);
			ar.setFailMsg(Const.UPDATE_FAIL);
		}
		return ar;
	}

	/**
	 * @api {post} /operLog/del  日志删除
	 * 
	 * @apiName del
	 * @apiGroup operLog
	 * @apiParam {Object} Page<TSProduct> 分页对象
	 * @apiSuccess {Object} obj 1.resMsg 2.obj
	 * @apiParam {Object} TSLog  日志对象
	 */
	@RequestMapping(value = "del", method = RequestMethod.POST)
	@ResponseBody
	public AjaxRes del(TSLog o) {
		AjaxRes ar = getAjaxRes();
		try {
			int res = service.deleteLog(o);
			if (res == 1)
				ar.setSucceedMsg(Const.DEL_SUCCEED);
			else
				ar.setFailMsg(Const.DEL_FAIL);
		} catch (Exception e) {
			logger.error(e.toString(), e);
			ar.setFailMsg(Const.DEL_FAIL);
		}
		return ar;
	}
}
